package sunwin.yoms.comm;

import jodd.datetime.JDateTime;
import org.springframework.aop.framework.AdvisedSupport;
import org.springframework.aop.framework.AopProxy;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

/**
 * Created by mt on 2015/8/1.
 */
@Component
public class YomsHelper {

    public JDateTime getCurDate() {
        return new JDateTime();
    }

    public Object getProxyTargetObject(Object proxy) throws Exception {
        Field h = proxy.getClass().getSuperclass().getDeclaredField("h");
        h.setAccessible(true);
        AopProxy aopProxy = (AopProxy) h.get(proxy);
        Field advised = aopProxy.getClass().getDeclaredField("advised");
        advised.setAccessible(true);
        return ((AdvisedSupport) advised.get(aopProxy)).getTargetSource().getTarget();
    }
}